$(function () {
    userName = localStorage.getItem("user");
    xianshi();
});
function car() {
    $.getJSON("easybuy/Car/selectCars",
        {"userName":userName},
        function (data) {
            var sumPrice = 0;
            $(".i_car").html("<div class=\"car_t\">购物车 [ <span>"+data.length+"</span> ]</div>\n" +
                "        <div class=\"car_bg\">\n" +
                "       \t\t<!--Begin 购物车未登录 Begin-->\n" +
                "            <!--End 购物车未登录 End-->\n" +
                "            <!--Begin 购物车已登录 Begin-->\n" +
                "            <ul class=\"cars\">\n" +
                "            \t\n" +
                "            </ul>\n" +

                "            <!--End 购物车已登录 End-->\n" +
                "        </div>");
            for (var i = 0; i < data.length; i++) {
                $(".i_car .cars").append("<li>\n" +
                    "                \t<div class=\"img\"><a href=\"#\"><img src=\"images/"+data[i].fileName+"\" width=\"58\" height=\"58\" /></a></div>\n" +
                    "                    <div class=\"name\"><a href=\"#\">"+data[i].name+"</a></div>\n" +
                    "                    <div class=\"price\"><font color=\"#ff4e00\">￥"+data[i].price+"</font> X"+data[i].count+"</div>\n" +
                    "                </li>");
                sumPrice = sumPrice+data[i].price*data[i].count;
            }
            $(".i_car .car_bg").append("<div class=\"price_sum\">共计&nbsp; <font color=\"#ff4e00\">￥</font><span>"+sumPrice+"</span></div>\n" +
                "<div class=\"price_a\"><a href=\"BuyCar.html\">去购物车结算</a></div>");
        });
}


function xianshi(){
    $.getJSON("easybuy/Car/selectCars",
        {"userName":userName},
        function (data) {
            var sumPrice = 0;
            if (data.length>0){
                $(".i_bg .car_tab").html("<tr>\n" +
                    "            <td class=\"car_th\" width=\"490\">商品名称</td>\n" +
                    "            <td class=\"car_th\" width=\"140\">属性</td>\n" +
                    "            <td class=\"car_th\" width=\"150\">购买数量</td>\n" +
                    "            <td class=\"car_th\" width=\"130\">小计</td>\n" +
                    "            <td class=\"car_th\" width=\"140\">返还积分</td>\n" +
                    "            <td class=\"car_th\" width=\"150\">操作</td>\n" +
                    "          </tr>");
                for (var i = 0; i < data.length; i++) {
                    $(".i_bg .car_tab").append("<tr>\n" +
                        "            <td>\n" +
                        "            \t<div class=\"c_s_img\"><img src=\"images/"+data[i].fileName+"\" width=\"73\" height=\"73\" /></div>\n" +
                        data[i].name +
                        "            </td>\n" +
                        "            <td align=\"center\">颜色：灰色</td>\n" +
                        "            <td align=\"center\">\n" +
                        "            \t<div class=\"c_num\">\n" +
                        "                    <input type=\"button\" value=\"\" onclick=\"jianUpdate1(jq(this));\" class=\"car_btn_1\" />\n" +
                        "<input type=\"hidden\" value=\""+data[i].count+"\" name=\"\" class=\"myinput\" />"+
                        "<input class='jiajian' type='hidden' value='"+data[i].id+"'>"+
                        "                \t<input type=\"text\" value=\""+data[i].count+"\" name=\"\" class=\"car_ipt\" readonly/>  \n" +
                        "                    <input type=\"button\" value=\"\" onclick=\"addUpdate1(jq(this));\" class=\"car_btn_2\" />\n" +
                        "                </div>\n" +
                        "            </td>\n" +
                        "            <td align=\"center\" style=\"color:#ff4e00;\">￥"+(data[i].price*data[i].count)+"</td>\n" +
                        "            <td align=\"center\">"+(26*data[i].count)+"R</td>\n" +
                        "            <td align=\"center\"><a href='javascript:void(0)' class='deletecar'>删除</a><input class='shanchu' type='hidden' value='"+data[i].id+"'>&nbsp; &nbsp;<a href=\"javascript:void(0)\" class='addCollect'>加入收藏</a></td>\n" +
                        "          </tr>");
                    sumPrice = sumPrice+data[i].price*data[i].count;
                }
                $(".i_bg .car_tab").append("<tr height=\"70\">\n" +
                    "          \t<td colspan=\"6\" style=\"font-family:'Microsoft YaHei'; border-bottom:0;\">\n" +
                    "            \t<label class=\"r_txt\"><a href='javascript:void(0)'>清空购物车</a></label>\n" +
                    "                <span class=\"fr\">商品总价：<b style=\"font-size:22px; color:#ff4e00;\">￥"+sumPrice+"</b></span>\n" +
                    "            </td>\n" +
                    "          </tr>\n" +
                    "          <tr valign=\"top\" height=\"150\">\n" +
                    "          \t<td colspan=\"6\" align=\"right\">\n" +
                    "            \t<a href=\"Index.html\"><img src=\"images/buy1.gif\" /></a>&nbsp; &nbsp; <a href=\"BuyCar_Two.html\"><img src=\"images/buy2.gif\" /></a>\n" +
                    "            </td>\n" +
                    "          </tr>");
            }else {
                $(".i_bg .car_tab").html("<tr height=\"70\">\n" +
                    "          \t<td colspan=\"6\" style=\"font-family:'Microsoft YaHei';font-size: 30px; border-bottom:0;text-align: center\">\n" +
                    "            \t购物车空空如也，快去购物吧！\n" +
                    "            </td>\n" +
                    "          </tr>\n" +
                    "          <tr valign=\"top\" height=\"150\">\n" +
                    "          \t<td colspan=\"6\" align=\"right\">\n" +
                    "            \t<a href=\"CategoryList.html\"><img src=\"images/buy1.gif\" /></a>&nbsp; &nbsp;\n" +
                    "            </td>\n" +
                    "          </tr>");
            }

        });
}

